﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Client.XML;
using Common;

namespace Client.Common
{
    public class Helper
    {
        private static PlanList MyPlanList = null;
        /// <summary>
        /// 将本地计划列表反序列为PlanList(用于客户端)
        /// </summary>
        /// <returns></returns>
        public static PlanList GetPlanList()
        {
            return GetPlanList(CommonData.XmlFilePath);
        }

        /// <summary>
        /// 将本地计划列表反序列为PlanList
        /// </summary>
        /// <param name="pPath"></param>
        /// <returns></returns>
        public static PlanList GetPlanList(string pPath)
        {
            //if (MyPlanList == null)
            //{
            //    MyPlanList = XmlOperator.GetPlanList(pPath);
            //}

            //MyPlanList = XmlOperator.GetPlanList(pPath);
            // 作为系统服务，无法及时获知文件更新
            MyPlanList = XmlOperator.GetPlanList(pPath);
            return MyPlanList;
        }

        public static void ClearCacheForPlanList()
        {
            MyPlanList = null;
        }

        /// <summary>
        /// 判断今天是否有计划
        /// </summary>
        /// <param name="pPl"></param>
        /// <param name="pTodayPlan"></param>
        /// <returns></returns>
        public static bool HasPlanedToday(PlanList pPl, out DayPlan pTodayPlan)
        {
            pTodayPlan = null;
            pTodayPlan = pPl.Plans.Find(p => p.Date == DateTime.Now.ToString("yyyy-MM-dd"));

            return pTodayPlan != null;
        }

        
    }


}